package per.lee.spingboothelper.utils;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class SlowSqlDistinct {


	public static void main(String[] args) throws IOException {
		File file = new File("D:\\慢sql分析.xls");

		List<String[]> readCellRangeAddress = POIUtil.readExcel(file);

		List<String> sqlList = readCellRangeAddress.stream().flatMap(x -> Arrays.stream(x)).distinct().collect(Collectors.toList());
		
		Map<String, String> sqlMap = new HashMap<String, String>();
		
		sqlList.forEach(sql->{
			String key = findKey(sql);
			sqlMap.put(key, sql);
		});
		sqlMap.entrySet().forEach(e->{
			System.out.println(e.getValue());
		});
	}
	public static String findKey(String s) {
		if(s.contains("where")) {
			return s.substring(0,s.indexOf("where"));
		}
		return s;
	}
	

}
